package com.situ.hospital.service.impl;

import com.situ.hospital.dao.IDepartmentDAO;
import com.situ.hospital.dao.Impl.DepartmentDAOImpl;
import com.situ.hospital.pojo.Department;
import com.situ.hospital.pojo.query.DepartmentQuery;
import com.situ.hospital.service.IDepartmentService;
import com.situ.hospital.util.PageResult;

import java.util.List;

public class DepartmentServiceImpl implements IDepartmentService {

    private IDepartmentDAO departmentDAO = new DepartmentDAOImpl();

    @Override
    public List<Department> selectAll() {
        return departmentDAO.selectAll();
    }

    @Override
    public PageResult<Department> selectByPage(DepartmentQuery departmentQuery) {
        List<Department> list = departmentDAO.selectByPage(departmentQuery);
        int totalCount = departmentDAO.selectTotalCount(departmentQuery);
        return new PageResult<>(0, "", totalCount, list);
    }

    @Override
    public void deleteById(int id) {
        departmentDAO.deleteById(id);
    }

    @Override
    public void deleteByAll(String[] ids) {
        for(String id : ids) {
            departmentDAO.deleteById(Integer.parseInt(id));
        }
    }

    @Override
    public void add(Department department) {
        departmentDAO.add(department);
    }

    @Override
    public Department selectById(int id) {
        return departmentDAO.selectById(id);
    }

    @Override
    public void update(Department department) {
        departmentDAO.update(department);
    }
}
